package com.epoint.common;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.druid.support.json.JSONUtils;

/**
 * @Description 通用返回类型
 * @author ylc
 */
public class Result {
	static String[] codeMsg = {"操作失败","操作成功","今日报价次数已达上限"};
	
	public static String returnCode(int code) {
		Map<String, String> result = new HashMap<String, String>();
		
		if(code < 0 || code >= codeMsg.length) {
			result.put("code", Integer.toString(code));
			result.put("msg", "状态信息码错误");
		}else {
			result.put("code", Integer.toString(code));
			result.put("msg", codeMsg[code]);
		}

		return JSONUtils.toJSONString(result);
	}
	
	/**
	 * 自定义返回提示信息
	 * @param code
	 * @param msg
	 * @return
	 */
	public static String returnCode(int code, String msg) {
		Map<String, String> result = new HashMap<String, String>();
		
		if(code < 0 || code >= codeMsg.length) {
			result.put("code", Integer.toString(code));
			result.put("msg", msg);
		}else {
			result.put("code", Integer.toString(code));
			result.put("msg", codeMsg[code]);
		}

		return JSONUtils.toJSONString(result);
	}
}
